package com.geor.gcv.core.process;

import org.opencv.core.Mat;
import org.opencv.imgproc.Imgproc;

/**
 * 二值化处理
 * 
 * @author geor.lusongnan
 *
 */
public class ThresholdProcess extends Process {

	private Process chain;
	private int blockSize = 0;
	private int constValue = 0;
	private Mat mat;

	public ThresholdProcess(Process chain, int blockSize, int constValue) {
		this.chain = chain;
		this.blockSize = blockSize;
		this.constValue = constValue;
	}

	public ThresholdProcess(Mat mat, int blockSize, int constValue) {
		super();
		this.blockSize = blockSize;
		this.constValue = constValue;
		this.mat = mat;
	}

	@Override
	public Mat process() {
		if (mat == null) {
			mat = chain.process();
		}
		Mat result = new Mat(mat.size(), mat.type());

		Imgproc.adaptiveThreshold(mat, result, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV,
				blockSize, constValue);

		return result;
	}

	@Override
	public String getProcessName() {
		return chain.getProcessName() + "-->二值化处理";
	}

	public void setConstValue(int constValue) {
		this.constValue = constValue;
	}

	public void setBlockSize(int blockSize) {
		this.blockSize = blockSize;
	}
}
